package com.example.rabbitmq.service;

import com.example.rabbitmq.doamin.Book;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

/**
 * <h3>springboot_rabbitmq</h3>
 * <p></p>
 *
 * @author : zhengyue
 * @date : 2020-05-06 10:40
 **/
@Service
public class BookService {

    @RabbitListener(queues = "rabbit.news")
    public void receive(Book book) {
        System.out.println("接收消息：" + book);
        //接收消息：Book{bookName='《西游记》', author='吴承恩'}
    }

    @RabbitListener(queues = "rabbit")
    public void receive2(Message message) {
        System.out.println(message.getBody());
        //[B@6a3b66e
        System.out.println(message.getMessageProperties());
        //MessageProperties [headers={__TypeId__=com.example.rabbitmq.doamin.Book},
        // contentType=application/json, contentEncoding=UTF-8, contentLength=0,
        // receivedDeliveryMode=PERSISTENT, priority=0, redelivered=false,
//         receivedExchange=exchange.fanout, receivedRoutingKey=, deliveryTag=1,
        // consumerTag=amq.ctag-Z60TyHOFk39LSXByFKjqFA, consumerQueue=rabbit]
    }
}
